package com.sunday.aomicaichang.ui.product;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.flyco.tablayout.SlidingTabLayout;
import com.sunday.common.adapter.MainFragmentPagerAdapter;
import com.sunday.common.base.BaseActivity;
import com.sunday.aomicaichang.R;
import com.umeng.socialize.UMShareAPI;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by yun_sheng on 2017/6/7.
 */

public class ProductActivity extends BaseActivity {
    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.slide_tab)
    SlidingTabLayout slideTab;
    @Bind(R.id.right)
    ImageView right;
    @Bind(R.id.view_pager)
    ViewPager viewPager;
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private final String[] mTitles = {
            "商品", "菜谱", "评价"
    };
    private long id;
    private String name;
    private int page;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product);
        ButterKnife.bind(this);
        name = getIntent().getStringExtra("name");
        id = getIntent().getLongExtra("id",0);
        page = getIntent().getIntExtra("page",0);
        initView();
    }

    @OnClick({R.id.right})
    void onClick(View v) {
        switch (v.getId()) {

        }
    }

    private void initView() {
        fragments.add(ProductDetailFragment.newInstance(id));
        fragments.add(ProductMenuFragment.newInstance(name,id));
        fragments.add(ProductAssessFragment.newInstance(id));
        viewPager.setAdapter(new MainFragmentPagerAdapter(getSupportFragmentManager(), mContext, fragments,
                R.array.buy_order_list_title));
        slideTab.setViewPager(viewPager, mTitles, this, fragments);
        viewPager.setCurrentItem(page, false);

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data);
    }
}
